package com.haifeng.asms.api.context;

import com.alibaba.fastjson.JSON;
import com.haifeng.asms.dao.model.dto.UserDto;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;

/**
 * <p>
 *  项目上下文信息
 * </p>
 *
 * @author: Haifeng
 * @date: 2020-06-23
 */
public class AsmsContext {

    public static UserDto getUser() {
        try {
            User user = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
            return JSON.parseObject(user.getUsername(), UserDto.class);
        }catch (Exception e){
            return null;
        }
    }
}
